﻿using IPR_StudyMeetingMrgSys.Enums;
using IPR_StudyMeetingMrgSys.Extension;
using IPR_StudyMeetingMrgSys.Models;
using IPR_StudyMeetingMrgSys.ViewModel;
using IPR_StudyMeetingMrgSys.Common;

using log4net;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Web;
using System.Web.Http;

namespace IPR_StudyMeetingMrgSys.Controllers
{
    public class ModuleButtonController : ApiController
    {
        ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        BLL.ModuleButton Bll = new BLL.ModuleButton();
        /// <summary>
        /// 添加模块
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/ModuleButton/Add")]
        public IHttpActionResult Add(Model.ModuleButton model)
        {
            //log.Info($"ModID:{model.ModID};ModName:{model.ModName};ModDesc:{model.ModDesc};ModParentID:{model.ModParentID};ModURL:{model.ModUrl};ModLevel:{model.ModLevel}");

            ResultMsg resultMsg = new ResultMsg();
            ////验证角色ID RID是否存在  
            //if (Bll.Exists(model.ModID))
            //{
            //    resultMsg.StatusCode = (int)StatusCodeEnum.Error;
            //    resultMsg.Info = "已经存在该模块ID";
            //    resultMsg.Data = "";
            //}
            //else
            //{
            //    Model.ModuleButton Mol = new Model.ModuleButton();
            //    Mol.ModID = model.ModID;
            //    Mol.ModName = model.ModName;
            //    Mol.ModParentID = model.ModParentID;
            //    Mol.ModUrl = model.ModUrl;
            //    Mol.ModDesc = model.ModDesc;
            //    Mol.ModOrderID = model.ModOrderID;
            //    Mol.ModLevel = model.ModLevel;
            //    long flag = Bll.Add(Mol);
            //    if (flag > 0)
            //    {
            //        resultMsg.StatusCode = (int)StatusCodeEnum.Success;
            //        resultMsg.Info = StatusCodeEnum.Success.GetEnumText();
            //        resultMsg.Data = flag;
            //    }
            //    else
            //    {
            //        resultMsg.StatusCode = (int)StatusCodeEnum.Error;
            //        resultMsg.Info = "添加失败";
            //        resultMsg.Data = flag;
            //    }
            //}

            return Json(resultMsg);
        }
        /// <summary>
       /// 得到模块列表
       /// </summary>
       /// <returns></returns>
        [HttpPost]
        [Route("api/ModuleButton/Sel")]
        public IHttpActionResult Sel()
        {
            log.Info($"获取模块列表");
            ResultMsg resultMsg = new ResultMsg();
            DataTable dt= Bll.GetAllList().Tables[0];
            if (dt.Rows.Count > 0)
            {
                resultMsg.StatusCode = (int)StatusCodeEnum.Success;
                resultMsg.Info = StatusCodeEnum.Success.GetEnumText();
                resultMsg.Data = dt;
            }
            else
            {
                resultMsg.StatusCode = (int)StatusCodeEnum.Success;
                resultMsg.Info = "没有获取到模块信息";
                resultMsg.Data = "";
            }
            return Json(resultMsg);
        }
        /// <summary>
        /// 删除模块ModID
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/ModuleButton/Del")]
        public IHttpActionResult Del(Model.ModuleButton model)
        {
            //log.Info($"删除模块");
            //log.Info($"ModID:{model.ModID};ModName:{model.ModName};ModDesc:{model.ModDesc};ModParentID:{model.ModParentID};ModURL:{model.ModUrl};ModLevel:{model.ModLevel}");

            ResultMsg resultMsg = new ResultMsg();

            //if (Bll.DeleteMod(model.ModID))
            //{
            //    resultMsg.StatusCode = (int)StatusCodeEnum.Success;
            //    resultMsg.Info = StatusCodeEnum.Success.GetEnumText();
            //    resultMsg.Data = "";
            //}
            //else
            //{
            //    resultMsg.StatusCode = (int)StatusCodeEnum.Success;
            //    resultMsg.Info = "删除信息失败";
            //    resultMsg.Data = "";
            //}
            return Json(resultMsg);
        }
        /// <summary>
        /// 更新模块
        /// </summary>
        /// <param name="model">mid</param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/ModuleButton/Edit")]
        public IHttpActionResult Edit(Model.ModuleButton model)
        {
            log.Info($"更新模块列表");
            ResultMsg resultMsg = new ResultMsg();
            //Model.ModuleButton Mol = new Model.ModuleButton();
            //Mol.ModID = model.ModID;
            //Mol.ModName = model.ModName;
            //Mol.ModParentID = model.ModParentID;
            //Mol.ModUrl = model.ModUrl;
            //Mol.ModDesc = model.ModDesc;
            //Mol.ModOrderID = model.ModOrderID;
            //Mol.ModLevel = model.ModLevel;
            //Mol.AutoID = model.AutoID;
            //if (Bll.Update(Mol))
            //{
            //    resultMsg.StatusCode = (int)StatusCodeEnum.Success;
            //    resultMsg.Info = StatusCodeEnum.Success.GetEnumText();
            //    resultMsg.Data = "";
            //}
            //else
            //{
            //    resultMsg.StatusCode = (int)StatusCodeEnum.Success;
            //    resultMsg.Info = "更新信息失败";
            //    resultMsg.Data = "";
            //}
            return Json(resultMsg);
        }
        
    }
}
